package cn.cyh.queue_service.controller;

import cn.cyh.queue_service.common.Result;
import cn.cyh.queue_service.model.dto.CallNextRequest;
import cn.cyh.queue_service.model.dto.CompleteServiceRequest;
import cn.cyh.queue_service.model.vo.QueueVO;
import cn.cyh.queue_service.service.QueueService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 叫号终端
 * @since 2025-04-10 10:45
 */
@RestController
@RequestMapping("/callTerminal")
public class CallTerminalController {

    @Resource
    private QueueService queueService;

    @RequestMapping("getWaitingQueuesByServiceType")
    @Operation(summary = "服务端", description = "获取队列数据")
    public Result<List<QueueVO>> getWaitingQueuesByServiceType() {
        return Result.success(queueService.getWaitingQueues());
    }

    @RequestMapping("getQueueHistoryByWindowId")
    @Operation(summary = "服务端", description = "获取窗口办理记录")
    public Result<List<QueueVO>> getQueueHistoryByWindowId(Long windowId) {
        return Result.success(queueService.getQueueHistoryByWindowId(windowId));
    }

    @RequestMapping("callNextCustomer")
    @Operation(summary = "服务端", description = "呼叫下一位")
    public Result<QueueVO> callNextCustomer(@RequestBody CallNextRequest request) {
        return Result.success(queueService.callNext(request));
    }

    @RequestMapping("startService")
    @Operation(summary = "服务端", description = "开始服务")
    public Result<Boolean> startService(String ticketNumber, Long windowId) {
        return Result.success(queueService.startService(ticketNumber, windowId));
    }

    @RequestMapping("completeService")
    @Operation(summary = "服务端", description = "完成服务")
    public Result<Boolean> completeService(@RequestBody CompleteServiceRequest request) {
        return Result.success(queueService.completeService(request));
    }

    @RequestMapping("markAsNoShow")
    @Operation(summary = "服务端", description = "未到场")
    public Result<Boolean> markAsNoShow(String ticketNumber, Long windowId) {
        return Result.success(queueService.markAsNoShow(ticketNumber, windowId));
    }

    @RequestMapping("getCurrentQueueByWindow")
    @Operation(summary = "服务端", description = "获取窗口当前叫号队列")
    public Result<QueueVO> getCurrentQueueByWindow(Long windowId) {
        return Result.success(queueService.getCurrentQueueByWindow(windowId));
    }
}
